package com.example.mushroom.controller;

import com.example.mushroom.entity.Statistics;
import com.example.mushroom.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @PostMapping
    public int insertStatistics(@RequestBody Statistics statistics) {
        return statisticsService.insertStatistics(statistics);
    }

    @GetMapping("/{id}")
    public Statistics selectStatisticsById(@PathVariable Integer id) {
        return statisticsService.selectStatisticsById(id);
    }

    @GetMapping
    public List<Statistics> selectAllStatistics() {
        return statisticsService.selectAllStatistics();
    }

    @PutMapping
    public int updateStatistics(@RequestBody Statistics statistics) {
        return statisticsService.updateStatistics(statistics);
    }

    @DeleteMapping("/{id}")
    public int deleteStatisticsById(@PathVariable Integer id) {
        return statisticsService.deleteStatisticsById(id);
    }

    @GetMapping("/page")
    public List<Statistics> selectStatisticsByPage(@RequestParam int offset, @RequestParam int limit) {
        return statisticsService.selectStatisticsByPage(offset, limit);
    }
}